package app.tool;

import java.io.File;
import java.util.Map;

import org.rygh.core.util.UIo;
import org.rygh.semantic.gui.swing.input.Input;
import org.rygh.semantic.model.ex.FactSet;
import org.rygh.semantic.model.rdf.Entity;

import wsi.match.Matcher;
import wsi.match.SubtreeMatch;
import wsi.script.AppConfig;
import wsi.subgraph.ExtractWorker;
import wsi.subgraph.tree.EntityTree;
import wsi.subgraph.tree.EntityTreeLoader;

public class checkMatch {

	public static void main(String[] args) {
		AppConfig.init();

		String xml_fname = "/home/nanmus/Experiments/runs/1123_l_yago_20_fb_instance_5/functions/discogs/getReleaseById/xmls/y_The_Blues_Brothers_(film).xml";
		String xml = UIo.readFile(new File(xml_fname));

		Entity entity = new Entity("y:The_Blues_Brothers_(film)", false);

		ExtractWorker extractor = new ExtractWorker(null, null);
		Map<Entity, FactSet> map = extractor.extract(entity);

		FactSet facts = new FactSet();

		for (FactSet j : map.values())
			facts.add(j);

		EntityTreeLoader loader = new EntityTreeLoader(entity, facts);
		EntityTree ent_tree = loader.load();

		Matcher matcher = new Matcher();

		Input input = new Input(entity, null, entity.getBodyString());
		SubtreeMatch sm = matcher.match(input, ent_tree, xml);

		if (sm == null)
			System.out.println("no match");
		else
			System.out.printf("match size %d", sm.size());
	}

}
